package com.qf.service.impl;

import com.qf.entity.SysRoleMenuKey;
import com.qf.exceptions.AddDataException;
import com.qf.exceptions.ResultCode;
import com.qf.mapper.SysRoleMenuDao;
import com.qf.pojo.CheckType;
import com.qf.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * @Author ztf
 * @Date 20:11 2022/1/10
 **/
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class RoleMenuServiceImpl implements RoleMenuService {
    private SysRoleMenuDao sysRoleMenuDao;

    @Autowired
    public void setSysRoleMenuDao(SysRoleMenuDao sysRoleMenuDao) {
        this.sysRoleMenuDao = sysRoleMenuDao;
    }

    @Override
    public void addRoleMenu(SysRoleMenuKey roleMenuKey) {
        Assert.isTrue(roleMenuKey.isEmpty(CheckType.ADD), () -> {
            throw new AddDataException("添加角色菜单失败-参数错误", ResultCode.FAIL);
        });
        sysRoleMenuDao.insert(roleMenuKey);
    }
}
